/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistence;

import database.DBConnection;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import model.Activity;
import model.Signup;

/**
 *
 * @author Martin Mohr Pedersen
 */
public class SignupDAO {

    public int countSignups(Activity activity) {
        String sql = "SELECT COUNT(*) AS count FROM signup WHERE activity_id = ?";
        Object[] args = new Object[] {activity.getId()};
        
        ArrayList<HashMap<String, Object>> results = DBConnection.getInstance().executeSelect(sql, args);

        String value = results.get(0).get("count").toString();
        return Integer.parseInt(value);
    }

    public void create(Signup signup) {
        
        String sql = "INSERT INTO signup (activity_id, guest_cpr, time) VALUES(?, ?, ?)";
        
        Object[] args = new Object[] {
            signup.getActivity().getId(),
            signup.getGuest().getCpr(),
            new Date()
        };
        
        DBConnection.getInstance().executeInsert(sql, args);
        
    }
}
